<template>
  <div class="container_edit">
    <div class="header">
      <p>公司介绍</p>
    </div>
    <div class="main">
      <el-form
        :model="user"
        :rules="rules"
        ref="user"
        label-width="150px"
        class=""
      >
        <el-form-item
          label="公司介绍："
          prop="signature"
        >
         <bg-editor
            :minHeight="300"
            :uploadUrl="upLoadUrl"
            :content="content"
            @editorData='editorInfo'
          >
          </bg-editor>
        </el-form-item>

        <el-form-item>
          <el-button
            type="primary"
            @click="handleSave('user')"
          >保存</el-button>
        </el-form-item>
      </el-form>
    </div>

  </div>
</template>

<script>
let CONSTANT = require("../../constant/constant.js");
let common = require("../../common.js");
export default {
  data() {
    return {
      upLoadUrl: "",
      content: "",
      user: {
        path: "",
        coverKey: "",
        id: ""
      },
      rules: {
        content: [
          { required: true, message: "请选择轮播图", trigger: "blur" }
        ]
      },
    };
  },
  mounted() {
    this.id = this.$router.currentRoute.query.id;
    let sessionId = sessionStorage.getItem("sessionId");
    this.currentPage = this.$router.currentRoute.query.pageIndex
      ? this.$router.currentRoute.query.pageIndex
      : 1;
    this.upLoadUrl =
      CONSTANT.URL.SYSTEM.UPLOADFILEBYCOS + "?sessionId=" + sessionId;
     this.getInfo();
  },
  components: {
    "bg-editor": () => import("../common/bg-editor.vue")
  },
  methods: {
    editorInfo(e) {
      this.content = e
    },
    getInfo: function() {
      let url = CONSTANT.URL.LIST.saveIntroduce+'companyProfile';
      common.get(url,this.id, res => {
        if (res.status == 200) {
          let data = res.data.bussData;
          this.user = data;
          $('#summernote').summernote('code',data)
        }
      });
    },
    handleSave: function(formName) {
      let param = {value:this.content}
      let url = CONSTANT.URL.LIST.saveIntroduce+'companyProfile';
      common.put(url, '',JSON.stringify(param) , res => {
        if (res.status == 200) {
          this.$message({
            type: "success",
            message: "保存成功！"
          });
        } else {
          this.$message({
            type: "warning",
            message: res.msg
          });
        }
      });
    },
  }
};
</script>
<style lang="scss" scoped>
.table-content {
  width: 500px;
  .table-item {
    position: relative;
    border: 1px solid #dcdfe6;
    i {
      position: absolute;
      right: -30px;
      top: 20px;
      cursor: pointer;
      font-size: 16px;
    }
    &:first-child {
      background-color: #409eff;
      color: #fff;
      border-right: 0px solid #dcdfe6;
      .table-list {
        padding: 0;
      }
    }

    .table-list {
      flex: 2;
      text-align: center;
      padding: 5px 0;
      .el-input {
        height: 70% !important;
        width: 90%;
      }
      &:first-child {
        flex: 3;
        border-right: 1px solid #dcdfe6;
      }
    }
  }
}
</style>
